#include <iostream>
using namespace std;

/*
    类中定义了虚函数，该类地址空间会多出一个指针，指向虚函数表
*/

class Animal
{
public:
    virtual void eat()
    {
        cout << "animal eat" << endl;
    }
};

class Dog : public Animal
{
public:
    void eat()
    {
        cout << "dog eat" << endl;
    }
};

class Cat : public Animal
{
public:
    void eat()
    {
        cout << "cat eat" << endl;
    }
};

class Sheep : public Animal
{
public:
    void eat()
    {
        cout << "sheep eat" << endl;
    }
};

class Pig : public Animal
{
public:
    void eat()
    {
        cout << "pig eat" << endl;
    }
};

// 封装函数，展示各种动物吃东西的行为
void showAnimalEat(Animal &animal)
{
    animal.eat();
}

// void showAnimalEat(Animal *animal)
// {
//     animal->eat();
// }

// void showAnimalEat(Animal animal) // 只有引用和指针的形参才具有多态性
// {
//     animal.eat();
// }

int main()
{
    cout << sizeof(Animal) << endl;
    cout << sizeof(Dog) << endl;
    cout << sizeof(Cat) << endl;
    cout << sizeof(Sheep) << endl;
    cout << sizeof(Pig) << endl;

    // showAnimalEat(&animal);
    // showAnimalEat(&dog);
    // showAnimalEat(&cat);
    // showAnimalEat(&sheep);
    // showAnimalEat(&pig);

    return 0;
}
